package com.lxf.education.service.impl;

import javax.annotation.Resource;

import com.lxf.education.dao.CourseMapper;
import com.lxf.education.dao.TeacherListMapper;
import com.lxf.education.pojo.CoursePojo;
import com.lxf.education.pojo.ReslutPojo;
import com.lxf.education.pojo.TeacherPojo;
import com.lxf.education.service.CourseService;
import com.lxf.education.utils.ResultVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author:LuoXingFa;
* @version:Date:2022年4月20日下午2:12:28
*/
@Service
public class CouseserviceImpl implements CourseService {

	//映射出course的接口类
	@Resource
	CourseMapper courseMapper;

	@Resource
	TeacherListMapper teacherListMapper;

	@Override
	public ResultVo getCourseByPage(Integer page, Integer limit) {
		// TODO Auto-generated method stub
		try {
			//计算出初始页
			Integer start = (page-1)*limit;
			//查询数据
			List<CoursePojo> coursePojo = courseMapper.getAllCourse(start,limit);
			//根据id查询到课程
			for(CoursePojo cPojo:coursePojo) {
//				//查询学生数量
				List<TeacherPojo>  teacherPojoList= teacherListMapper.getTeacherById(cPojo.getTid());
				cPojo.setTpojo(teacherPojoList);
			}

			//查询总条数
			int count = courseMapper.finCount();
			ResultVo successVo = ResultVo.getSuccessVo("success",coursePojo);
			//将总条数设置进去
			successVo.setCount(count);
			return successVo;

		}catch (Exception e){
			e.printStackTrace();
			return ResultVo.getFailVo("fails");
		}
	}

	@Override
	public ResultVo findAll() {
		return null;
	}
}
